﻿<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<%@taglib prefix="logic" uri="http://struts.apache.org/tags-logic"%>
<%@taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<jsp:useBean id="productBean" class="by.grsu.bso.beans.ProductUtilBean" scope="application" />
<jsp:useBean id="cartBean" class="by.grsu.bso.beans.ShoppingCartItemUtilBean" scope="application" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<logic:notPresent name="user" scope="session">
	<logic:redirect href="../createUser.do"></logic:redirect>
</logic:notPresent>

<logic:present name="user" scope="session">
		<c:if test="${sessionScope.user.isBlocked == false}">
				<c:if test="${sessionScope.user.role == 1}">
					<logic:redirect href="/info_pages/not_exist.jsp"></logic:redirect>	
				</c:if>
		</c:if>



<html>
<head>
  <link rel= "stylesheet" type="text/css" href="CSS/shopping_cart.css" />
  <script type="text/javascript" src="JS/shopping_cart.js"></script>
  <title></title>
</head>

<body>
	<c:set var="cartItems" value="${applicationScope.cartBean.getCartItems(sessionScope.user.id)}"/>
	<c:set var="counterProduct" value="0"/>
	<c:set var="totalPrice" value="0"/>
    <div  class="main">
        <div  class="header" align="center">Корзина</div>
        <form action="delete_cart_item.do" method="post">
        <div id="check_boxer">
 
		<c:forEach var="cartItem" items="${cartItems}">
			<c:set var="product" value="${applicationScope.productBean.getProduct(cartItem.productId)}"/>
			<c:set var="counterProduct" value="${counterProduct+1}"/>
			<c:set var="totalPrice" value="${totalPrice+product.price*cartItem.quantity}"/>
			
	        <div class="cover_product">
	            <div style="float:left" class="product">
	                <img src="${product.imageBase64}" align="left" height="90" width="60"/>
	                &nbsp;&nbsp;<a href="product.jsp?product=${product.id}">${product.name}</a><br><br>
	                &nbsp;&nbsp;${product.autor}, ${product.yearPublication}
	            </div>
	            <div  class="text_product1">
	                <input name="cart_item_count${cartItem.id}" type="text" value="${cartItem.quantity}" onkeyup="return test(this);" onchange="return test(this);" onkeydown="return test(this);" maxlength="4" />
	            </div>
	            <div class="text_product2">
	                <font color="#000000" size="5">${product.price} руб.</font>
	            </div>
	            <div class="text_product3">
	                <input name="cart_items" type="checkbox" id="checkbox" value="${cartItem.id}"/>
	            </div>
	
	        </div>
        
        </c:forEach>
        </div>


<c:choose>

<c:when test="${sessionScope.user.role == 2}">
	<div class="footer">
        <div align="center">Итого ${counterProduct} товар, на сумму: ${totalPrice} руб.</div>
        <div align="center">пересчитать<input type="radio" name="cart_operation" value="recalculation_cart" onClick="onCheck()"/><br></div>
        <div align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        удалить<input type="radio" name="cart_operation" value="delete_cart" onClick="offCheck()" /><br></div>
        <div align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        заказать<input type="radio" name="cart_operation" value="order_cart" onClick="offCheck()"/><br><br></div>
        <div align="center"><input type="submit" value="Выполнить" class="button-order"/></div>
        <a href="../">На главную</a>
        </div>			
</c:when>
<c:when test="${sessionScope.user.role == 3}">
	<div align="center">Войдите в систему, для оформления заказа.</div>					
</c:when>
</c:choose>    

    </form>

    </div>

</body>

</html>
</logic:present>